package top.kaoshanji.p2ch17a;

import top.kaoshanji.y1constant.FileConstant;

import java.io.IOException;
import java.io.PrintWriter;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.stream.Stream;

/**
 * 代码清单-p2ch17a-545页a：在流中读取、处理和写入等操作
 * author kaoshanji
 * ^_^
 * create time 2025/3/11 18:03
 */
public class StreamInAndOut {

    // 将 StreamInAndOut.java 文件复制到该目录下
    static String path = FileConstant.LOCAL_ROOT_PATH.concat("p2ch17a545页a//");

    public static void main(String[] args) {

        try (Stream<String> input = Files.lines(Paths.get(path.concat("StreamInAndOut.java")));
             PrintWriter output = new PrintWriter(path.concat("StreamInAndOut.txt"))) {

            // 将读取到的每行转换成大写，然后写入文件，再输出出来
            input.map(String::toUpperCase)
                    .forEachOrdered(output::println);

        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }


}
